﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Payton.WP7.Common;
using Payton.WP7.ViewModel;

namespace Payton.WP7.Views
{
    public partial class SettingView : PhoneApplicationPage
    {
        SettingViewModel _vm;
        public SettingView()
        {
            InitializeComponent();
            DataContext = _vm = new SettingViewModel();

            this.Loaded += (o, e) =>
            {
                var aib1 = new ApplicationBarIconButton
                {
                    IconUri = new Uri("/Images/AppBarIcons/appbar.check.rest.png", UriKind.Relative),
                    Text = AppResx.SaveText,
                };

                aib1.Click += ok_Click;

                var aib2 = new ApplicationBarIconButton
                {
                    IconUri = new Uri("/Images/AppBarIcons/refresh.png", UriKind.Relative),
                    Text = AppResx.ResetText,
                };

                aib2.Click += reset_Click;

                this.ApplicationBar.Buttons.Add(aib1);
                this.ApplicationBar.Buttons.Add(aib2);
            };
        }

        private void reset_Click(object sender, EventArgs e)
        {
            _vm.ResetSetting();
        }

        private void ok_Click(object sender, EventArgs e)
        {
            PhoneApplicationController.ApplyLanguageSetting();
            PhoneApplicationController.ApplyTheme();

           NavigationService.Navigate(new Uri("/Views/MainView.xaml", UriKind.Relative));
        }
    }
}